<template>
  <el-row :gutter="20" type="flex" justify="center">
    <el-col :span="10">
      <el-tag v-show="option.input"> 请输入参数 </el-tag>
      <div v-for="(value, index) in option.input" :key="index">
        <el-input
        class="input"
          v-model="params[index]"
          @input="chekData(index, $event)"
        >
          <template slot="prepend">{{ value }}</template></el-input
        >
      </div>
      <div class="ratio-row">      
        <el-radio v-show="index === 4 || index === 3" v-model="race" label="0.93"
        >亚洲人</el-radio
      >
      <el-radio v-show="index === 4 || index === 3" v-model="race" label="1"
        >白种人</el-radio
      >
      <el-radio v-show="index === 4 || index === 3" v-model="race" label="0.87"
        >黑种人</el-radio
      ></div>
    </el-col>
    <el-col :span="10">
      <el-tag v-show="option.input"> 结果 </el-tag>
      <el-input
        :disabled="true"
        style="margin-top: 5px"
        :value="computResults[index].toFixed(2)"
        v-for="(value, index) in option.output"
        :key="index"
        ><template slot="prepend">{{ value }}</template></el-input
      ></el-col
    >
  </el-row>
</template>

<script>
export default {
  name: "Computed",
  props: ["option"],
  data() {
    return {
      index: 0,
      params: ["", "", "", ""],
      results: ["", "", "", "", "", "", "", ""],
      race: "",
    };
  },
  watch: {
    option() {
      this.index = this.option.index;
    },
  },
  methods: {
    chekData(index, event) {
      let a = Number(event);
      if (isNaN(a)) {
        this.$alert("参数错误");
        this.$set(this.params, index, "");
      }
    },
  },
  computed: {
    computResults() {
      if (this.index === 1) {
        return [
          Math.exp(
            0.376 * Math.log(Number(this.params[1])) -
              0.012 * Number(this.params[1]) -
              58.8 / Number(this.params[0]) +
              5.63
          ),
          Math.exp(
            0.544 * Math.log(Number(this.params[1])) -
              0.0151 * Number(this.params[1]) -
              74.4 / Number(this.params[0]) +
              5.48
          ),
        ];
      } else if (this.index === 2) {
        return [
          Number(this.params[0] + Number(this.params[1])),
          Number(this.params[3]) + Number(this.params[2]),
          Number(this.params[3]) +
            Number(this.params[2]) +
            Number(this.params[0]) +
            Number(this.params[1]),
          Number(this.params[3]) +
            Number(this.params[2]) +
            Number(this.params[0]),
          Number(this.params[4]) + Number(this.params[1]),
          100 *
            (Number(this.params[4]) /
              (Number(this.params[3]) +
                Number(this.params[2]) +
                Number(this.params[0]))),
          100 *
            ((Number(this.params[4]) + Number(this.params[1])) /
              (Number(this.params[3]) +
                Number(this.params[2]) +
                Number(this.params[0]) +
                Number(this.params[1]))),
          100 *
            (Number(this.params[1]) /
              (Number(this.params[3]) +
                Number(this.params[2]) +
                Number(this.params[0]) +
                Number(this.params[1]))),
        ];
      } else if (this.index === 3) {
        return [
          this.race *
            1.08 *
            (0.043 * Number(this.params[0]) -
              0.029 * Number(this.params[1]) -
              2.49),
          this.race *
            1.1 *
            (0.0576 * Number(this.params[0]) -
              0.0269 * Number(this.params[1]) -
              4.34),
          87.2 - 0.18 * this.params[1],
        ];
      } else if (this.index === 4) {
        return [
          this.race *
            1.08 *
            (0.0395 * Number(this.params[0]) -
              0.025 * Number(this.params[1]) -
              2.6),
          this.race *
            1.15 *
            (0.0443 * Number(this.params[0]) -
              0.026 * Number(this.params[1]) -
              2.89),
          89.1 - 0.19 * this.params[1],
        ];
      }else if(this.index===5){
        return [
          Math.exp((((1.2669+(0.0174*Number(this.params[1])))*Number(this.params[0]))/100-1.2933)),
          Math.exp((((1.3731+(0.0164*Number(this.params[1])))*Number(this.params[0]))/100-1.2782)),
          86.21
        ]
      }else if(this.index===6){
        return [
          Math.exp((((1.5016+(0.0119*Number(this.params[1])))*Number(this.params[0]))/100-1.5974)),
          Math.exp((((1.48+(0.0127*Number(this.params[1])))*Number(this.params[0]))/100-1.4057)),
          88.88
        ]
      }
    },
  },
};
</script>
<style lang='less'>
.el-tag{
  font-size: 28px;
  height: 58px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #e5e9f2;
  color: black;
}
.el-col{
  font-size: 28px;
}
.el-input__inner{
  color: black;
    height: 58px;
}
.el-input.is-disabled .el-input__inner{
  color: black;
}
.ratio-row{
  box-sizing: border-box;
   display: flex;
   justify-content: space-between;
   padding: 20px;
}
.el-radio{
  display: flex;
  align-items: center;
}
.el-radio__label{
  font-size: 28px;
  color: black;
}
  .el-input{
        margin-top: 5px;

    font-size: 28px;
    color: black;
    border-color: black;
    .el-input-group__prepend{
      color:black;
      height: 58px;
    }
  }
</style>